package common;

import common.GameConstants;

import java.awt.*;

public class Position {

    private int x, y;

    private GameConstants.direction direction;

    //SETTERS
    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void setDirection(GameConstants.direction direction) {
        this.direction = direction;
    }

    //GETTERS
    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public GameConstants.direction getDirection() {
        return direction;
    }

    public Point asPoint(){
        return new Point(getX(), getY());
    }


    //CONSTRUCTORS
    public Position(int x, int y, GameConstants.direction direction){
        setPosition(x,y);
        this.direction = direction;
    }

    /**
     * @param x x-coordinate
     * @param y y-coordinate
     */
    public Position(int x, int y){
        setPosition(x,y);
        direction = null;
    }


    /**
     * helper method for setting the position
     * @param x
     * @param y
     */
    private void setPosition(int x, int y){
        if(x >= 0 && x < GameConstants.boardWidth &&
                y >= 0 && y < GameConstants.boardHeight){
            this.x = x;
            this.y = y;
        }
        else{
            throw new IllegalArgumentException("Position must be 0 or higher and below boardWidth. Got: " + x + " " + y );
        }
    }

    @Override
    public String toString() {
        return "Position[" + x + " " + y +" " + direction + "]";
    }
}
